package legoLab05;

import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.addon.RCXLightSensor;


public class GoalSensor {
	RCXLightSensor ls;
	int threshold = 40;
	int goalLightVal;
	
	public GoalSensor(SensorPort p){
		ls = new RCXLightSensor(p);
		ls.setFloodlight(true);
	}
	
	public void calibrate(){
		String goal = "Goal";
		int lightValue = 0;

		while (Button.ENTER.isPressed());

		LCD.clear();
		LCD.drawString("Press ENTER", 0, 0);
		LCD.drawString("to callibrate", 0, 1);
		LCD.drawString(goal, 0, 2);
		while( !Button.ENTER.isPressed() ){
			lightValue = ls.getNormalizedLightValue();
			LCD.drawInt(lightValue, 4, 10, 2);
			LCD.refresh();
		}
		goalLightVal = lightValue;
	}
	
	public boolean isGoal(){
		int read = ls.getNormalizedLightValue();
		return (read > (goalLightVal - threshold) && read < (goalLightVal + threshold));
	}
}
